package com.xiaolin.dao;

import com.xiaolin.pojo.Message;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author XiaoLin
 * @date 2019/2/25 09:09
 */
@org.apache.ibatis.annotations.Mapper
public interface MessageMapper extends Mapper<Message> {

    @Select("select * from message where send_uid = #{uid} or receive_uid = #{uid} ORDER BY send_last_date desc")
    @Results(id = "message", value = {
            @Result(property = "mid", column = "mid"),
            @Result(property = "sendUid", column = "send_uid"),
            @Result(property = "receiveUid", column = "receive_uid"),
            @Result(property = "gid", column = "gid"),
            @Result(property = "sendLastDate", column = "send_last_date"),
            @Result(property = "positionState", column = "position_state"),
            @Result(property = "messageContextList", many = @Many(select = "com.xiaolin.dao.MessageContextMapper.findByMid"), column = "mid")
    })
    List<Message> findMessageByUId(String uid);

    @Select("select * from message where mid = #{mid}")
    @ResultMap("message")
    Message findMessageByMid(Integer mid);

    @Select("select * from message where ( send_uid = #{uid} and receive_uid=#{receiveUid} ) or ( send_uid = #{receiveUid} and receive_uid=#{uid} ) ")
    @ResultMap("message")
    Message findMessageByUIdAndRid(@Param("uid") String uid, @Param("receiveUid") String receiveUid);
}
